<template>
	<view class="beijingse" v-if="pageShow">
		<!-- 规格 -->
			<u-popup :show="show" @close="show=false">
		            <view class="mainpadding">
		                <view class="flexbetween">
							<view class="sptp">
								<image class="" :src="dataAll.image_text" mode=""></image>
							</view>
							<view class="" style="width: 75%;">
								<view class="titletext xiaohei yhxk">{{dataAll.name}}</view>
								<template v-if="ly!=3">
									<view class="bigtext fonweight xiaocheng margin_top">¥{{dataAll.price}}</view>
								</template>
								<template  v-if="ly==3">
									<view class="flexleft margin_top">
										<view class="bigtext fonweight xiaocheng margin_right2">¥{{dataAll.fg_price}}</view>
										<view class="strongtext fonweight xiaohui zhonghuax">¥{{dataAll.price}}</view>
									</view>
								</template>
							</view>
		                </view>
						<view class="flexbetween margin_top5">
							<view class="ershil fonweight xiaohei ">购买数量</view>
							<u-number-box button-size="36" color="#000000" bgColor="#F7F7F7" iconStyle="color: #fff"
								v-model="buynumber"></u-number-box>
							<!-- <view class="jianbox flexbetween">
								<view class="" style="padding-left: 10rpx;">
									<u-icon name="minus" color="#B4B4B4" size="14"></u-icon>
								</view>
								<view class="biak"></view>
								<view class="ershiba xiaohei textcenter" style="width: 70rpx;">1</view>
								<view class="biak"></view>
								<view class="" style="padding-right: 10rpx;">
									<u-icon name="plus" color="#000" size="16"></u-icon>
								</view>
							</view> -->
						</view>
						<view class="bigbtn margin_top6" @click="ggclose">{{buy_type==0?"加入购物车":"立即购买"}}</view>
		            </view>
				</u-popup>
		<view class="" style="padding-bottom: 60rpx;">
			<u-swiper :list="dataAll.images_text" circular height="375px" radius="0"></u-swiper>
			<view class="mainpadding">
				<view class="ffffff radius mainpadding">
					<view class="flexbetween">
						<template v-if="ly!=3">
							<view class="titletext xiaocheng fonweight">￥
								<text class="xiaocheng fonweight" style="font-size: 48rpx;">{{dataAll.price}}</text>
							</view>
						</template>
						<template v-if="ly==3">
							<view class="flexleft">
								<view class="titletext xiaocheng fonweight margin_right2">￥
									<text class="xiaocheng fonweight" style="font-size: 48rpx;">{{dataAll.fg_price}}</text>
								</view>
								<view class="strongtext xiaohui fonweight">￥
									<text class="xiaohui fonweight zhonghuax" style="font-size: 30rpx;">{{dataAll.price}}</text>
								</view>
							</view>
							
						</template>
						<view class="xiaohui ershil">销量{{Number(dataAll.sales) + Number(dataAll.base_sales)}}</view>
					</view>
					
					<view class="titletext xiaohei margin_top">{{dataAll.name}}</view>
				</view>
			</view>
			<view class="mainpadding ffffff margin_top" style="padding-bottom: 150rpx;">
				<view class="sanshier textcenter xiaohei">商品详情</view>
				<view class="margin_top">
					<u-parse :content="dataAll.content"></u-parse>
				</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="ffffff mainpadding gudingdb flexbetween" v-if="ishome==0 || ly==2">
			<view class="flexleft" style="margin-left: 30rpx;">
				<view class="margin_right5"  @click="tzsy">
					<u-icon name="home" color="#333333" size="28"></u-icon>
					<view class="smalltext textcenter xiaohui">首页</view>
				</view>
				<button class="dibubox" hover-class="none" open-type="contact" bindcontact="handleContact" session-from="sessionFrom">
					<view class="">
						<u-icon name="kefu-ermai" color="#333333" size="28"></u-icon>
						<view class="smalltext textcenter xiaohui">客服</view>
					</view>
				</button>
			</view>
			<view class="flexleft" v-if="ly!=4">
				<view class="jrbtn flexcenter" @click="buytype(0)">加入购物车</view>
				<view class="lbtn flexcenter" @click="buytype(1)">立即购买</view>
			</view>
			<view class="flexleft" v-else>
				<view class="maibtn flexcenter" @click="buytype(1)">立即购买</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				pageShow:false,
				listid:"",
				dataAll:{},
				buynumber:1,
				buy_type:0,
				ly:1,//1=普通商品,2=换货,3=复购专区,4=会员购买
				ishome:0,//是否是首页进来的
			}
			
		},
		onLoad(options) {
			this.ly = options.ly
			this.listid = options.id
			if(options.ishome){
				this.ishome = options.ishome
			}
			this.getDetail()
		},
		methods: {
			ggclose() {
				this.show = false
				if (this.buy_type == 0) {
					this.addcar()
				} else {
					let data = {
						ly:this.ly,//1=普通商品,2=换货,3=复购专区,4=会员购买
						type: "detail", //detail=商品详情,cart=购物车
						data: [{
							goods_id: this.listid,
							number: this.buynumber
						}]
					}
					uni.navigateTo({
						url: '/pages_homepage/querendd?msg=' + encodeURIComponent(JSON.stringify(data))
					})
				}
			},
			addcar() {
				httpRequest.request('/api/cart/addCart', 'POST', {
					goods_id: this.dataAll.id,
					number: this.buynumber,
					data_type:this.ly
				}).then(res => {
					httpRequest.toast(res.msg)
				})
			},
			buytype(value) {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url:"/pages/login/login"
					})
					return false
				}
				this.buy_type = value
				this.show = true
			},
			getDetail() { //获取轮播图
				httpRequest.request('/api/goods/goodsDetail', 'GET', {
					goods_id: this.listid
				}).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				}).catch(err => {})
			},
			tzsy() {
				uni.reLaunch({
					url: '/pages/homepage'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.jianbox{
		width: 178rpx;
		height: 48rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		opacity: 1;
		border: 1rpx solid #D2D2D2;
	}
	.biak{
		width: 1rpx;
		height: 47rpx;
		background-color:#D2D2D2;
	}
	.sptp{
		width: 134rpx;
		height: 134rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		image{
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			width: 100%;
			height: 100%;
		}
	}
	.lbtn {
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		height: 76rpx;
		background-color: #FF7510;
		width: 208rpx;
		border-radius: 0 45rpx 45rpx 0rpx;
	}
	.maibtn {
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		height: 76rpx;
		background-color: #FF7510;
		width: 208rpx;
		border-radius: 45rpx;
	}

	.jrbtn {
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		height: 76rpx;
		background-color: #FFB801;
		width: 208rpx;
		border-radius: 45rpx 0 0 45rpx;
	}
</style>